﻿using Rougamo.Context;
using Rougamo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace AOP.Rougamo
{
    // 方法A数据监控
    public class TestAAttribute : MoAttribute
    {
        // 改为所有public方法有效，不论是实例方法还是静态方法
        public override AccessFlags Flags => AccessFlags.Public;

        public override void OnEntry(MethodContext context)
        {
            // 从context对象中能取到包括入参、类实例、方法描述等信息
            Console.WriteLine("方法A执行前");
            var reqArg = context.Arguments;
            if (reqArg != null)
                Console.WriteLine($"获取到请求参数为{string.Join(",", reqArg)}");
            Task.Run(() => Dispatched.TestB());
        }
        public override void OnException(MethodContext context)
        {
            Console.WriteLine($"节点A方法执行异常，错误消息：{context.Exception.Message}", context.Exception);
        }

        public override void OnSuccess(MethodContext context)
        {
            var ReturnValue = context.ReturnValue;
            if (ReturnValue != null)
                Console.WriteLine($"获取A到执行结果为{ReturnValue}");
            Console.WriteLine("方法A执行成功后");
        }
    }
}
